const { baseUrl } = require('./env.js').dev;

module.exports = {
  request: function(url, data = {}){
    let fullUrl = baseUrl + url;
    //console.log(data);
    // Promise写法
    return new Promise((resolve, reject) => {
      wx.request({
        url: fullUrl,
        method: 'POST',
        data,
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          'x-requested-with': 'XMLHttpRequest'
        },
        success(res){
          console.log(res);
          resolve(res.data);
        },
        fail(error){
          reject('未知错误：http request receive fail.');
          //console.log(error);
        }
      })
    });
  }
}